package cn.lhjl.day09.多线程;

public class BaoZhiPu extends Thread {
    BaoZhi baoZhi;

    public BaoZhiPu(BaoZhi baoZhi) {
        this.baoZhi = baoZhi;
    }

    @Override
    public void run() {
        int count = 0;
        while (true){
            synchronized (baoZhi){
                if (baoZhi.flag){
                    try {
                        baoZhi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
                if (count%2==0){
                    baoZhi.baoZhiPi="薄皮";
                    baoZhi.baoZhiXian="肉馅";
                }else {
                    baoZhi.baoZhiPi="厚皮";
                    baoZhi.baoZhiXian="豆沙馅";
                }
                System.out.println("开始做"+baoZhi.baoZhiPi+baoZhi.baoZhiXian+"包子");
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("做好了");
                count++;
                baoZhi.flag=true;
                baoZhi.notify();
            }
        }
    }
}
